﻿using System;
using System.Collections;
using System.Collections.Generic;

using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.DAL.Dao
{
    /// <summary>
    /// 功能：     ServiceInfo业务接口的实现
    /// 作者：     lwl
    /// 日期：     2011/10/14
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    [Serializable]
    public class ServiceInfoSqlMapDao : BaseSqlMapDao, IServiceInfoDao
    {
        private static ServiceInfoSqlMapDao instance = null;
        private static object syncRoot = new object();

        private ServiceInfoSqlMapDao()
        {
            //
            // TODO: 此处添加ServiceInfoSqlMapDao的构造函数
            //
        }
        public static IServiceInfoDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new ServiceInfoSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectServiceInfoByMaxCounts", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary> 
        /// <returns></returns>
        public System.Collections.Generic.IList<ServiceInfo> GetList()
        {
            try
            {
                return ExecuteQueryForList<ServiceInfo>("SelectServiceInfo", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过参数得到某种服务状态的列表
        /// by amos
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<ServiceInfo> GetListByStatus(object objParameters)
        {
            try
            {
                //string sql = base.GetSqlString("SelectServiceInfoByStatus", objParameters);

                return ExecuteQueryForList<ServiceInfo>("SelectServiceInfoByStatus", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary> 
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<ServiceInfo> GetListByParameters(object objParameters)
        {
            try
            {
                Handler.ServiceHandler handler = new Handler.ServiceHandler();
                ExecuteWithRowDelegate("SelectServiceInfoByParameters", objParameters, new IBatisNet.DataMapper.RowDelegate(handler.GetFullList));
                return handler.servicelist;
                //return ExecuteQueryForList<ServiceInfo>("SelectServiceInfoByParameters", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="ServiceID"></param>
        /// <returns></returns>
        public ServiceInfo GetDetail(Hashtable ht)
        {
            try
            {
                ServiceInfo serviceinfo = ExecuteQueryForObject<ServiceInfo>("SelectServiceInfo", ht) as ServiceInfo;
                Handler.ServiceHandler handler = new Handler.ServiceHandler();
                return handler.GetFullService(serviceinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="serviceinfo"></param>
        /// <returns></returns>
        public object Add(ServiceInfo serviceinfo)
        {
            //int id = GetId("ServiceInfo");
            //serviceinfo.ServiceID = id;

            try
            {
                return ExecuteInsert("InsertServiceInfo", serviceinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="serviceinfo"></param>
        /// <returns></returns>
        public int Update(ServiceInfo serviceinfo)
        {
            try
            {
                return ExecuteUpdate("UpdateServiceInfo", serviceinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ServiceID"></param>
        /// <returns></returns>
        public int Delete(System.String serviceid)
        {
            try
            {
                return ExecuteDelete("DeleteServiceInfo", serviceid);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="serviceinfo"></param>
        /// <returns></returns>
        public int Delete(ServiceInfo serviceinfo)
        {
            try
            {
                return ExecuteDelete("DeleteServiceInfo", serviceinfo.ServiceID);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<ServiceInfo> GetServiceInfoListPage(object objParameters)
        {
            try
            {
                // 在Handler中将UserName及CategoryName的值赋到ServiceInfo中      Add by Vinlon  2011-11-04
                //ExecuteQueryForList<ServiceInfo>("GetServiceInfoPage", objParameters);
                Handler.ServiceHandler handler = new Handler.ServiceHandler();
                ExecuteWithRowDelegate("GetServiceInfoPage", objParameters, new IBatisNet.DataMapper.RowDelegate(handler.GetFullList));
                return handler.servicelist;
            }
            catch
            {

                throw;
            }
        }

        /// <summary>
        /// 通过用户ID和服务ID得到用户其它服务
        /// 创建人:Wilson
        /// 创建时间：2011-10-25
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<ServiceInfo> GetUserServiceElseByUserId(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<ServiceInfo>("SelectUserServiceElseByUserId", objParameters);
            }
            catch
            {

                throw;
            }
        }

        /// <summary>
        /// 通过用户ID得到用户服务
        /// 创建人：Wilson
        /// 创建时间：2011-10-26
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public IList<ServiceInfo> GetServiceListByUserId(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<ServiceInfo>("SelectListByUserId", objParameters);
            }
            catch
            {

                throw;
            }
        }



        /// <summary>
        /// 通过用户ID得到好评的总数
        /// 创建人：Wilson
        /// 创建时间：2011-10-26
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public int GetGoodRateSumByUserId(string userId)
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectGoodRateSumByUserId", userId);
            }
            catch
            {

                throw;
            }
        }

        /// <summary>
        /// 通过用户ID得到差评的总数
        /// 创建人：Wilson
        /// 创建时间：2011-10-26
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public int GetBadRateSumByUserId(string userId)
        {
            return (int)ExecuteQueryForObject("SelectBadRateSumByUserId", userId);
        }

        /// <summary>
        /// 根据标题或描述的模糊匹配查询服务信息
        /// </summary>
        /// <param name="ht"></param>
        /// <returns></returns>
        public IList<Model.ServiceInfo> GetListByTitleOrDesc(Hashtable ht)
        {
            try
            {
                Handler.ServiceHandler handler = new Handler.ServiceHandler();
                ExecuteWithRowDelegate("SelectListByTitleOrDesc", ht, new IBatisNet.DataMapper.RowDelegate(handler.GetFullList));
                return handler.servicelist;
            }
            catch
            {
                throw;
            }
        }

    }
}
